# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/13 19:09
# @Author   : Robot-Zsj
"""
description:

i:
2 3 3 1

o:
5
"""

x, y, cntx, cnty = map(int, input().split())


def check(k):
    A = k // x  # 1-k范围内x倍数的数量
    B = k // y  # 1-k范围内y倍数的数量
    C = k // (x * y)  # 1-k范围内x*y倍数的数量

    return max(0, cntx - (B - C)) + max(0, cnty - (A - C)) <= k - A - B + C


def getResult():
    low = 1
    high = 1000000000

    while low <= high:
        mid = (low + high) // 2

        if check(mid):
            high = mid - 1
        else:
            low = mid + 1

    return low


print(getResult())
